<?php
namespace app\controllers\api\account;

use fate\http\Request;
use app\models\User;
use app\libs\Util;
use app\services\MailService;

class EditpwdbymailcodeController extends \fate\web\PureController {
    public function run() {
        $req = Request::getInstance();

        $email = Util::plainText($req->getParameter('email'));
        $code = Util::plainText($req->getParameter('code'));
        $pwd = $req->getParameter('pwd');

        $service = new MailService();
        $rs = $service->validateFindCode($email, $code);

        if(!$rs) {
            $this->ajaxReturn(null, 200002);
            exit;
        }

        $pwd = md5($pwd);
        $user = new User();
        $user->updateByCondition(['password' => $pwd], "email='{$email}'");

        $this->ajaxReturn(null);
    }
}
